(function (aopc) {
    aopc.addExpandPage(826, function (get) {
        const Md5 = get('UtilsCommon', 'Md5');
        const Common = get('UtilsCommon', 'Common');

        return {
            expandInit() {
                this.isRemember = true;
                const pageAxis = this.props.getPageAxis();
                this.check_view = this.getProperty('check_view');
                this.bottom_device_info = this.getProperty('bottom_device_info');
                this.login_dialog_view = this.getProperty('login_dialog_view');
                this.close_img1 = this.getProperty('close_img1');
                this.close_img1.isVisible = !!pageAxis.isIndex;
                this.loginKey = "joerogjeopqrijgoeqilrjgoqijerg";
                this.loginNameProperty = this.getViewProperty(this.login_dialog_view, 'LoginName');
                this.loginPasswordProperty = this.getViewProperty(this.login_dialog_view, 'LoginPassword');

                this.initLoginName();
            },
            initLoginName() {
                try {
                    let obj = {};
                    const loginStr = Common.getStorage(this.loginKey);
                    if (loginStr) obj = JSON.parse(window.atob(loginStr));

                    const { LoginName, LoginPassword } = obj;
                    this.setPropertyValue(this.loginNameProperty, LoginName);
                    this.setPropertyValue(this.loginPasswordProperty, LoginPassword);
                }
                catch (e) {
                    console.error(e);
                }
            },
            setPropertyValue(p, v) {
                p.value = v;
                p.setValue && p.setValue(v);
            },
            setInit() {
                const pageAxis = this.props.getPageAxis();
                if (!window.loginUser) {
                    if (pageAxis.pageConfig.isLogin) {
                        this.login_dialog_view.isVisible = true;
                    }
                }
                this.bottom_device_info.text = '设备序号：' + this.visitUser.DisplayIndex + '&emsp;设备角色：' + (this.visitUser.IsPresident ? '主席' : '列席') + '<br/>设备MAC：' + (this.visitUser.MacAddress || '未知');
            },
            show(callback) {
                this.loginCallback = callback;
                const [p1, p2] = this.login_dialog_view.properties;
                if (window.loginUser) {
                    const { DisplayIndex, IsPresident, MacAddress } = this.visitUser;
                    const data = { DisplayIndex, MacAddress: MacAddress || '未知', RoleName: IsPresident ? '主席' : '列席', UserName: window.loginUser.UserName };
                    this.eventActions.entityEdit.setPropertiesValue(p2.properties, data, true, true);
                    this.setIsVisible(p1, false);
                    this.setIsVisible(p2, true);
                }
                else {
                    this.initLoginName();
                    this.setIsVisible(p2, false);
                    this.setIsVisible(p1, true);
                }
                this.login_dialog_view.setIsVisible(true);
            },
            setIsVisible(p, v) {
                p.isVisible = v;
                p.setIsVisible && p.setIsVisible(v);
            },
            expandSetEntityData({ entityData }) {
                if (this.isRemember) {
                    const { LoginName, LoginPassword } = entityData;
                    Common.setStorage(this.loginKey, window.btoa(JSON.stringify({ LoginName, LoginPassword })));
                }
                else Common.removeStorage(this.loginKey);

                entityData.LoginPassword = Md5(entityData.LoginPassword);
                return entityData;
            },
            successCallback({ data }) {
                window.loginUser = data;
                if (this.isRemember) Common.setStorage('loginUserInfo', JSON.stringify(data));
                else Common.removeStorage('loginUserInfo');

                this.login_dialog_view.setIsVisible(false);
                this.loginCallback && this.loginCallback();
            },
            logout() {
                Common.removeStorage('loginUserInfo');
                window.loginUser = null;
                this.login_dialog_view.setIsVisible(false);
            },
            setRemember() {
                this.isRemember = !this.isRemember;
                this.check_view.style.backgroundColor = this.isRemember ? '#5b93dd' : 'transparent';
                this.check_view.properties[0].setIsVisible(this.isRemember);
                this.check_view.refresh();
            },
            setSelfHide({ property, e }) {
                if (window.location.href.indexOf('index.html') > 0) {
                    const ele = property.getElement();
                    if (ele === e.target) property.setIsVisible(false);
                }
            }
        }
    });
})(window.aopc);